package game.metalmax.module.character
{
	import game.metalmax.animation.CharacterSOB;
	import game.metalmax.animation.zone.SceneZone;
	import game.metalmax.entity.character.Character;
	import game.metalmax.entity.character.Hero;
	
	import showtime.framework.core.pattern.Singleton;
	import showtime.framework.engine.World2D;

	public class CharacterManager extends Singleton
	{
		public var self:Hero = null;

		public var heros:Array = null;
		
		public static function getInstance():CharacterManager
		{
			return CharacterManager(Singleton.getInstanceOrCreate(CharacterManager));
		}
		
		override protected function initialize():void
		{
			heros = [];
		}
	
		
		public function parseCharacterToHero(character:Character):Hero
		{
			var hero:Hero = new Hero();

			hero.animationConfigID = character.animationConfigID;
			hero.animationName = character.animationName;
			hero.dialogID = character.aiConfigID;
			hero.direction = character.direction;
			hero.graphicID = character.graphicID;
			hero.solid = false;
			hero.id = character.id;
			hero.name = character.name;
			hero.spawnPoint = character.spawnPoint.clone();
			hero.velocity = character.velocity;
			hero.visible = character.visible;
			
			return hero;
		}
		
		public function addHeroToTeam(hero:Hero):void
		{
			var target:CharacterSOB = SceneZone(World2D.scene).target;
			
			while (target.followTarget != null)
			{
				target = target.followTarget;
			}			
			
			target.setFollowTarget(Character(hero), target.getBackPoint());

		}
		
	}
}